﻿Imports SS
Imports SS.Databases
Imports SS.Databases.Connecter
Imports SS.ApplicationBlock

Public Class Organization

	Public Function LoadDataOrganizationData(ByVal id As String) As DataTable
		Dim connOra As New DBOracle(Common.Utility.ConnectString, False)
		Dim dt As DataTable = LoadDataOrganizationDataLv1(id, connOra)

		If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then

			'-----------------------------LV2-----------------------------
			If dt.Rows(0)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(0)("OFFICER_DOWNLINE_LEFT").ToString, "2", dt, connOra)
			Else
				InsertEmptySide("2", dt)
			End If

			If dt.Rows(0)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(0)("OFFICER_DOWNLINE_RIGHT").ToString, "2", dt, connOra)
			Else
				InsertEmptySide("2", dt)
			End If
			'----------------------------------------------------------

			'-----------------------------LV3-----------------------------
			If dt.Rows(1)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(1)("OFFICER_DOWNLINE_LEFT").ToString, "3", dt, connOra)
			Else
				InsertEmptySide("3", dt)
			End If

			If dt.Rows(1)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(1)("OFFICER_DOWNLINE_RIGHT").ToString, "3", dt, connOra)
			Else
				InsertEmptySide("3", dt)
			End If

			If dt.Rows(2)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(2)("OFFICER_DOWNLINE_LEFT").ToString, "3", dt, connOra)
			Else
				InsertEmptySide("3", dt)
			End If

			If dt.Rows(2)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(2)("OFFICER_DOWNLINE_RIGHT").ToString, "3", dt, connOra)
			Else
				InsertEmptySide("3", dt)
			End If
			'----------------------------------------------------------

			'-----------------------------LV4-----------------------------
			If dt.Rows(3)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(3)("OFFICER_DOWNLINE_LEFT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(3)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(3)("OFFICER_DOWNLINE_RIGHT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(4)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(4)("OFFICER_DOWNLINE_LEFT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(4)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(4)("OFFICER_DOWNLINE_RIGHT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(5)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(5)("OFFICER_DOWNLINE_LEFT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(5)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(5)("OFFICER_DOWNLINE_RIGHT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(6)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(6)("OFFICER_DOWNLINE_LEFT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If

			If dt.Rows(6)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(6)("OFFICER_DOWNLINE_RIGHT").ToString, "4", dt, connOra)
			Else
				InsertEmptySide("4", dt)
			End If
			'----------------------------------------------------------

			'-----------------------------LV5-----------------------------
			If dt.Rows(7)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(7)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(7)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(7)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(8)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(8)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(8)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(8)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(9)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(9)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(9)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(9)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(10)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(10)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(10)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(10)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(11)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(11)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(11)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(11)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(12)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(12)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(12)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(12)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(13)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(13)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(13)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(13)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(14)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(14)("OFFICER_DOWNLINE_LEFT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If

			If dt.Rows(14)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(14)("OFFICER_DOWNLINE_RIGHT").ToString, "5", dt, connOra)
			Else
				InsertEmptySide("5", dt)
			End If
			'----------------------------------------------------------

			'-----------------------------LV5-----------------------------
			If dt.Rows(15)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(15)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(15)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(15)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(16)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(16)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(16)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(16)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(17)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(17)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(17)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(17)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(18)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(18)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(18)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(18)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(19)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(19)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(19)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(19)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(20)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(20)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(20)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(20)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(21)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(21)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(21)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(21)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(22)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(22)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(22)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(22)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(23)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(23)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(23)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(23)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(24)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(24)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(24)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(24)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(25)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(25)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(25)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(25)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(26)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(26)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(26)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(26)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(27)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(27)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(27)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(27)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(28)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(28)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(28)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(28)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(29)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(29)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(29)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(29)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(30)("OFFICER_DOWNLINE_LEFT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(30)("OFFICER_DOWNLINE_LEFT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If

			If dt.Rows(30)("OFFICER_DOWNLINE_RIGHT") IsNot Convert.DBNull Then
				LoadDataOrganizationDataNextLv(dt.Rows(30)("OFFICER_DOWNLINE_RIGHT").ToString, "6", dt, connOra)
			Else
				InsertEmptySide("6", dt)
			End If
			'----------------------------------------------------------
			Return dt
		Else
			Return Nothing
		End If

	End Function

	Public Function LoadDataOrganizationDataLv1(ByVal id As String, ByVal connOra As DBOracle) As DataTable
		Dim sb As New Text.StringBuilder
		'sb.AppendLine("select '1' LV, OFFICER_ID,OFFICER_APP_ID,OFFCIER_APP_TEL,OFFICER_FIRSTNAME_THA,OFFICER_LASTNAME_THA,OFFICER_STATUS,OFFICER_DOWNLINE_LEFT,OFFICER_DOWNLINE_RIGHT ")
		'sb.AppendLine("from RNW_VW_OFFICER Where OFFICER_ID = '" & id & "'")

		sb.AppendLine("SELECT A.*,B.LEFT_RV,B.RIGHT_RV,C.INCOME_MYSELF FROM (")
		sb.AppendLine("    select '1' LV, OFFICER_ID,OFFICER_APP_ID,OFFCIER_APP_TEL,OFFICER_FIRSTNAME_THA,OFFICER_LASTNAME_THA,OFFICER_STATUS,OFFICER_DOWNLINE_LEFT,OFFICER_DOWNLINE_RIGHT")
		sb.AppendLine("    from " & Common.Utility.Schema & ".RNW_VW_OFFICER")
		sb.AppendLine("    Where OFFICER_ID = '" & id & "'")
		sb.AppendLine(") A LEFT OUTER JOIN (    ")
		sb.AppendLine("    SELECT RV.OFFICER_ID,RV.LEFT_RV_SUMMARY LEFT_RV,RV.RIGHT_RV_SUMMARY  RIGHT_RV")
		sb.AppendLine("    FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_RV RV")
		sb.AppendLine("    WHERE RV.SUMMARY_ID IN (select max(summary_id) from " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_RV where RNWT_SUM_OFFICER_RV.OFFICER_ID = '" & id & "')")
		sb.AppendLine(") B ON A.OFFICER_ID =  B.OFFICER_ID")
		sb.AppendLine("LEFT OUTER JOIN (")
		sb.AppendLine("SELECT INC.OFFICER_ID,INC.INCOME_MYSELF FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_INCOME INC WHERE SUMMARY_ID IN (SELECT MAX(SUMMARY_ID) FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_INCOME WHERE RNWT_SUM_OFFICER_INCOME.OFFICER_ID = '" & id & "')")
		sb.AppendLine(") C ON A.OFFICER_ID =  C.OFFICER_ID")

		Return connOra.GetDataTable(sb.ToString, "dtOrganization")
	End Function

	Public Sub LoadDataOrganizationDataNextLv(ByVal id As String, ByVal lv As String, ByVal dtResult As DataTable, ByVal connOra As DBOracle)
		Dim sb As New Text.StringBuilder
		'sb.AppendLine("select '" & lv & "' LV, OFFICER_ID,OFFICER_APP_ID,OFFCIER_APP_TEL,OFFICER_FIRSTNAME_THA,OFFICER_LASTNAME_THA,OFFICER_STATUS,OFFICER_DOWNLINE_LEFT,OFFICER_DOWNLINE_RIGHT ")
		'sb.AppendLine("from RNW_VW_OFFICER Where OFFICER_ID = '" & id & "'")

		sb.AppendLine("SELECT A.*,B.LEFT_RV,B.RIGHT_RV,C.INCOME_MYSELF FROM (")
		sb.AppendLine("    select '" & lv & "' LV, OFFICER_ID,OFFICER_APP_ID,OFFCIER_APP_TEL,OFFICER_FIRSTNAME_THA,OFFICER_LASTNAME_THA,OFFICER_STATUS,OFFICER_DOWNLINE_LEFT,OFFICER_DOWNLINE_RIGHT")
		sb.AppendLine("    from " & Common.Utility.Schema & ".RNW_VW_OFFICER")
		sb.AppendLine("    Where OFFICER_ID = '" & id & "'")
		sb.AppendLine(") A LEFT OUTER JOIN (    ")
		sb.AppendLine("    SELECT RV.OFFICER_ID,RV.LEFT_RV_SUMMARY LEFT_RV,RV.RIGHT_RV_SUMMARY  RIGHT_RV")
		sb.AppendLine("    FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_RV RV")
		sb.AppendLine("    WHERE RV.SUMMARY_ID IN (select max(summary_id) from " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_RV where RNWT_SUM_OFFICER_RV.OFFICER_ID = '" & id & "')")
		sb.AppendLine(") B ON A.OFFICER_ID =  B.OFFICER_ID")
		sb.AppendLine("LEFT OUTER JOIN (")
		sb.AppendLine("SELECT INC.OFFICER_ID,INC.INCOME_MYSELF FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_INCOME INC WHERE SUMMARY_ID IN (SELECT MAX(SUMMARY_ID) FROM " & Common.Utility.Schema & ".RNWT_SUM_OFFICER_INCOME WHERE RNWT_SUM_OFFICER_INCOME.OFFICER_ID = '" & id & "')")
		sb.AppendLine(") C ON A.OFFICER_ID =  C.OFFICER_ID")

		Dim dt As DataTable = connOra.GetDataTable(sb.ToString, "dtOrganization")

		If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
			Dim dr As DataRow = dtResult.NewRow
			dr(0) = dt.Rows(0)(0)
			dr(1) = dt.Rows(0)(1)
			dr(2) = dt.Rows(0)(2)
			dr(3) = dt.Rows(0)(3)
			dr(4) = dt.Rows(0)(4)
			dr(5) = dt.Rows(0)(5)
			dr(6) = dt.Rows(0)(6)
			dr(7) = dt.Rows(0)(7)
			dr(8) = dt.Rows(0)(8)
			dr(9) = dt.Rows(0)(9)
			dr(10) = dt.Rows(0)(10)
			dr(11) = dt.Rows(0)(11)
			dtResult.Rows.Add(dr)
		Else
			InsertEmptySide(lv, dtResult)
		End If

	End Sub

	Public Sub InsertEmptySide(ByVal lv As String, ByVal dtResult As DataTable)
		Dim dr As DataRow = dtResult.NewRow
		dr(0) = lv
		dr(1) = Convert.DBNull
		dr(2) = Convert.DBNull
		dr(3) = Convert.DBNull
		dr(4) = Convert.DBNull
		dr(5) = Convert.DBNull
		dr(6) = "N"
		dr(7) = Convert.DBNull
		dr(8) = Convert.DBNull
		dr(9) = 0
		dr(10) = 0
		dr(11) = 0
		dtResult.Rows.Add(dr)
	End Sub

End Class
